// 
// File:   add_variables.h
// Author: cionescu
//
// Created on March 13, 2007, 12:15 AM
//

#ifndef _add_variables_H
#define	_add_variables_H
#include <string>
#include <vector>
#include <map>
//#include <iterator>
#include <cudd.h>
#include "dd/dd_cudd.h"

#define VAR_MAX_ENCODING 10
static int varnum=0;
class add_variables {
  typedef std::pair<const char*, DdNode*> mapping_type;
  typedef std::vector<DdNode*> vars_type;
  typedef std::map<const char*, DdNode*> map_type;
  
  DdManager* manager;
  vars_type vars;
  map_type mapping;
  
  public:
  add_variables(DdManager* _m)
  :manager(_m){}
  
  // allocates a new variable and appends to internal
  // data structures
  void
  new_variable(int _enc, char* _name){
    int end = vars.size();
    std::string name;
    char* buffer;
    
    printf("new variable declared. name:%s encoding:%d\n", _name,_enc);
    for (int i = 0; i<_enc; i++) { 
      buffer = new char[10];
      sprintf(buffer, "%s.%d", _name, i);
      printf(buffer); printf("\n");
      DdNode* var = DD_Var(manager, varnum++);
      mapping.insert(mapping_type(buffer, var));
      vars.push_back(var);
    }
  }
  
  DdNode**
  get_raw_vector() {
    DdNode** vect = new DdNode*[vars.size()];
    for (int i = 0; i < vars.size(); i++) {
      vect[i] = vars[i];
    }
    return vect;
  }
  
  int
  get_encoding_size() {
    return vars.size();
  }
  
  void
  print() {
    
  }
};

#endif	/* _add_variables_H */

